package com.zerui.manager.web;

import com.zerui.authority.annotation.Authorize;
import com.zerui.basedata.client.dto.OrganizationTreeDTO;
import com.zerui.cola.dto.PageResponse;
import com.zerui.cola.dto.Response;
import com.zerui.cola.dto.SingleResponse;
import com.zerui.manager.web.cmd.AccessAuthOrgBindCmd;
import com.zerui.manager.web.cmd.AccessAuthOrgQryCmd;
import com.zerui.manager.web.vo.AccessAuthOrgPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @create_time 2023-08-23 15:33
 */
@Validated
@Api(value = "门禁授权部门绑定", tags = "门禁设备管理")
@RestController
@RequestMapping("/api/v1/access/auth/org")
public class AccessAuthOrgController {

    @Resource
    private AccessAuthOrgService accessAuthOrgService;

    @ApiOperation(value = "门禁授权组织树", tags = "门禁授权管理")
    @GetMapping("/tree")
    public SingleResponse<List<OrganizationTreeDTO>> getOrgTree(@RequestParam String orgName) {
        return accessAuthOrgService.getOrganizationTree(orgName);
    }

    @ApiOperation(value = "门禁授权组织分页列表", tags = "门禁授权管理")
    @PostMapping("/getPageList")
    public PageResponse<AccessAuthOrgPageVO> getPageList(@RequestBody @Validated AccessAuthOrgQryCmd accessAuthOrgQryCmd) {
        return accessAuthOrgService.getPageList(accessAuthOrgQryCmd);
    }

    @ApiOperation(value = "门禁授权 - 部门绑定", tags = "门禁授权管理")
    @PostMapping("/bind")
    public Response add(@RequestBody @Validated AccessAuthOrgBindCmd accessAuthOrgBindCmd) {
        return accessAuthOrgService.add(accessAuthOrgBindCmd);
    }

    @ApiOperation(value = "门禁授权 - 取消绑定", tags = "门禁授权管理")
    @PostMapping("/cancel/bind")
    public Response delete(@RequestBody @Validated AccessAuthOrgBindCmd accessAuthOrgBindCmd) {
        return accessAuthOrgService.delete(accessAuthOrgBindCmd);
    }

}
